/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import dao.HangSanXuatDAO;
import javax.swing.JOptionPane;
import pojo.HangSanXuat;

/**
 *
 * @author LaiHuynh
 */
public class ThemHangSanXuat extends javax.swing.JInternalFrame {

    /**
     * Creates new form ThemHangSanXuat
     */
    public ThemHangSanXuat() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jtfHangsx = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jbThoat = new javax.swing.JButton();
        jbThem = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("HÃNG SẢN XUẤT");

        jLabel1.setText("Tên Hãng Sãn Xuất");

        jbThoat.setText("Thoát");
        jbThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbThoatActionPerformed(evt);
            }
        });

        jbThem.setText("Thêm");
        jbThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbThemActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addComponent(jLabel1)
                .addGap(31, 31, 31)
                .addComponent(jtfHangsx, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbThem)
                .addGap(18, 18, 18)
                .addComponent(jbThoat)
                .addGap(40, 40, 40))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtfHangsx, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbThem)
                    .addComponent(jbThoat))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbThemActionPerformed
        try { 
            String str = this.jtfHangsx.getText();
            HangSanXuat hsx = new HangSanXuat();
            int sl = HangSanXuatDAO.getSoLuong();
            hsx.setMaHangsx(sl+1);
            hsx.setTenHang(str);
            HangSanXuatDAO.themHangSanXuat(hsx);
            JOptionPane.showMessageDialog(this, "Thêm Thành Công");
        } catch(Exception ex) {
            JOptionPane.showMessageDialog(this, ex);
        }
    }//GEN-LAST:event_jbThemActionPerformed

    private void jbThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbThoatActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jbThoatActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton jbThem;
    private javax.swing.JButton jbThoat;
    private javax.swing.JTextField jtfHangsx;
    // End of variables declaration//GEN-END:variables
}
